/**
 * 
 * 获取永久二维码
 * 
 * 适用常见：统计用户来源、帐号绑定等
 * 
 */

const routerApi = require('../../../utils/routeString.js')(__filename, __dirname);
const token = require('../wechat_jssdk/jssdk_access_token');
const request = require('../../../utils/request.js')
var qs = require('querystring');

const getQr = async function (req, res) {

    console.log(1);

    try {
        let tokenStr = await token({ body: { appid: 'wx8c6852df92fcfc6b' } });

        let postData = JSON.stringify({ "expire_seconds": 604800, "action_name": "QR_SCENE", "action_info": { "scene": { "scene_id": 123 } } });

        let result = await request({
            hostname: "api.weixin.qq.com",
            port: 443,
            path: "/cgi-bin/qrcode/create?access_token=" + tokenStr,
            method: "POST",
            data: postData,
            headers: {
                'Content-Type': 'text/plain;charset=UTF-8'
            }
        })

        console.log("qr: " + result);

    } catch (error) {
        console.log(error);
    }

}

// setTimeout(() => {
//     getQr();
// }, 2000);

server.post({ path: routerApi, name: routerApi }, getQr);
